home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Lib / =DTS.framework.fns next >
Encoding:
Text File  |  1992-10-22  |  46.4 KB  |  786 lines  |  [TEXT/MPS ]

  1. /************** AEConnect.c **************/
  2.  
  3. void            InitConnectAppleEvents(void);
  4. /* This function initializes the connect AppleEvents stuff.  It needs to be
  5. ** called so that DTS.framework applications can connect with other applications
  6. ** specific to a targeted window. */
  7.  
  8. OSErr            SendConnect(FileRecHndl frHndl, char *theLocNBPType);
  9. /* This is the function that is called to establish a connection to another
  10. ** DTS.framework-based application.  The "other" DTS.framework application is probably
  11. ** the same application on another machine.  This code does a bit more than simply
  12. ** connecting to another application.  It targets a specific window within that application.
  13. ** It doesn’t just target zone/machine/application, which is the granularity that AppleEvents
  14. ** gives you.  It also passes back and forth some information that is kind of a pain to get,
  15. ** but is nice to have.  One such piece of information is the user name.  This needs to be
  16. ** sent.  It can’t be determined from the message from an AppleEvent.  The sender sends
  17. ** the user name, and the receiver returns the remote user name.  The user name is
  18. ** placed in the document record for the window to be used if you wish. */
  19.  
  20. WindowPtr        GetAEWindow(long windID_0, long windID_1);
  21. /* This function is called to determine which window, if any, is the designated
  22. ** target window.  The window ID’s are determined when the connection is established. */
  23.  
  24.  
  25.  
  26. /************** AERequired.c **************/
  27.  
  28. void            InitRequiredAppleEvents(void);
  29. /* Intializes AppleEvent dispatcher table for the required events.  It also
  30. ** determines if the machine is PPCBrowser and AppleEvent capable.  If so,
  31. ** the booleans gHasAppleEvents and gHasPPCToolbox are set true.  This function
  32. ** must be the first AppleEvents initialization DTS.framework function called, as the
  33. ** other functions depend on the booleans being set correctly. */
  34.  
  35.  
  36.  
  37. /************** AEUtils.c **************/
  38.  
  39. void            DoHighLevelEvent(EventRecord *event);
  40. /* This function simply calls AEProcessAppleEvent and reports any errors. */
  41.  
  42. OSErr            GetTargetInfo(AEAddressDesc targetDesc, StringPtr zone, StringPtr machine,
  43.                               StringPtr application);
  44. /* This function returns the zone, machine, and application name for the
  45. ** indicated target descriptor. */
  46.  
  47. OSErr            MakeTarget(AEAddressDesc *target, Boolean sendDirect, short replyMode, Str255 prompt,
  48.                            Str255 applListLabel, PPCFilterProcPtr portFilter, char *theLocNBPType);
  49. /* Creates a TargetID.  If sendDirect is TRUE, the target is specified by setting
  50. ** a ProcessSerialNumber to kCurrentProcess.  This has the advantage of sending
  51. ** the message directly to ourselves, bypassing ePPC and gaining about a 10-15x
  52. ** speed improvement.  If sendDirect is FALSE, we see if we have the
  53. ** PPCToolBox.  If not, then we are forced to do a direct send.  If we do have
  54. ** the PPCToolbox, then we call PPCBrowser.  We then look at the reply, and
  55. ** factor in the mode we are going to use in AESend.  If that mode is
  56. ** kAEWaitReply and the user selected us as the target, we have to turn that
  57. ** into a direct send.  This is because the AppleEvent Manager will otherwise
  58. ** post the event as a high-level event.  However, we are busy waiting for a
  59. ** reply, not looking for events, so we’ll hang.  We avoid this by forcing a
  60. ** direct send. */
  61.  
  62. Boolean            MissedAnyParameters(AppleEvent *message);
  63. /* Used to check for any unread required parameters. Returns true if we
  64. ** missed at least one. */
  65.  
  66. void            NotifyCancel(void);
  67. /* Use this function to cancel a notification.  Simply call it for a resume.  It checks if
  68. ** there is a notification to cancel, and if there is one, it cancels it. */
  69.  
  70. void            NotifyUser(void);
  71. /* When an Apple Event is received, call this.  If the application isn’t the front-most
  72. ** application, a notification is posted. */
  73.  
  74.  
  75.  
  76. /************** CtlHandler.c **************/
  77.  
  78. short            CNum2Ctl(WindowPtr window, short ctlNum, ControlHandle *ctl);
  79. /* This function converts a control number to a control handle.  The function
  80. ** simply walks the window’s control list counting down until it has reached
  81. ** the right control number.  It also returns the number of controls traversed.
  82. ** While often this will be the same as the control number passed in, if the
  83. ** number passed in is greater than the number of controls in the list, then
  84. ** the number returned is the number of controls in the list. */
  85.  
  86. short            Ctl2CNum(ControlHandle ctl);
  87. /* This function converts a control handle to a control number.  The function
  88. ** simply walks the window’s control list and counts how many controls it
  89. ** has to traverse before finding the target control.  The smallest control
  90. ** number that can be returned is 1.  This makes control numbers similar to
  91. ** dialog item numbers. */
  92.  
  93. void            DoCtlActivate(WindowPtr window);
  94. /* This function reactivates the last active TextEdit or List control for
  95. ** the indicated window. */
  96.  
  97. void            GetCheckBoxValues(WindowPtr window, Boolean checkBoxVal[]);
  98. /* This function returns all the checkBox values into the designated array.
  99. ** The function walks the control list, and when it finds a checkBox control,
  100. ** it gets the control value and places it in the next position in the array.
  101. ** This allows a single call to retrieve all the checkBox values at once. */
  102.  
  103. short            GetRadioButtonChoice(WindowPtr window, short famNum);
  104. /* This function returns which radio button is selected for a particular
  105. ** family of radio buttons.  It finds the radio button of the target family
  106. ** with the lowest control number and it subtracts this number from the
  107. ** selected radio button of the same family.  This gives a relative radio
  108. ** button number as a return result.  This way the position of the family
  109. ** of radio buttons can change in the window and the return result is the
  110. ** same.  The family number is stored in the control’s refCon field. */
  111.  
  112. short            IsCtlEvent(WindowPtr window, EventRecord *event, ControlHandle *ctl, short *action);
  113. /* This function currently handles events for TextEdit, List, and button
  114. ** controls in a window.  It also handles the window scrollbars and scrolling
  115. ** of the window.  If the event is handled, it returns non-zero.  See the
  116. ** document “=Using CtlHandler.c” for more information. */
  117.  
  118.  
  119.  
  120. /************** File.c **************/
  121.  
  122. OSErr            DefaultInitDocument(FileRecHndl frHndl, short version,
  123.                                     short numUndos, short numSaveUndos);
  124. /* This function does the standard document initialization.  The standard document uses
  125. ** the hierarchical document package TreeObj.  Read the TreeObj documentation for
  126. ** more information. */
  127.  
  128. OSErr            DisposeDocument(FileRecHndl frHndl);
  129. /* This function is automatically called by such functions as DisposeOneWindow.  It
  130. ** calls the designated free document procedure, which by default is FreeDocument.
  131. ** The free document procedure is responsible for disposing of any and all handles
  132. ** that were created by the init document procedure. */
  133.  
  134. OSErr            NewDocument(FileRecHndl *returnHndl, OSType sftype, Boolean incTitleNum);
  135. /* This function needs to be called by the application at appropriate times.  It
  136. ** calls the designated init document procedure, which by default is InitDocument.
  137. ** The init document procedure is responsible for creating any and all initial
  138. ** handles for the document.  New documents will be created with a default title.  This
  139. ** title is created by appending a number to the corresponding STR# individual string.
  140. ** The STR# resource ID #259 holds the default text for the window titles.  Which string
  141. ** number is determined by the OSType array gTypeList.  gTypeList contains all of the
  142. ** file types that can be opened by the application.  The list is walked, and the location
  143. ** in the gTypeList array that holds the correct file type is used as an index into
  144. ** the STR# resource.  If the file type isn’t found in the list, then the first string
  145. ** in the STR# resource is used.
  146. ** The next greatest integer is appended to the end of the individual string selected
  147. ** for the document.  If incTitleNum is true, then the global integer is first incremented
  148. ** prior to appending the number.
  149. ** If you want to create a document with the title found in the 'WIND' resource, first
  150. ** call NewDocument().  After you have the frHndl for the document, set the file name
  151. ** in the (*frHndl)->fileState.fss.name field to an empty string.  When the window is
  152. ** opened for this document, if this name is an empty string, it titles the window
  153. ** according to what is found in the 'WIND' resource for that window.  If this field is
  154. ** not an empty string, then the 'WIND' title is overridden, and the file name is used. */
  155.  
  156. OSErr            OpenDocument(FileRecHndl *result, FSSpecPtr fileToOpen, char permission);
  157. /* This function does the human-interface thing for opening a document.  It
  158. ** also calls NewDocument() to initialize a document.  To actually read in
  159. ** the data, OpenDocument() calls the designated read document procedure, which by
  160. ** default is ReadDocument().  The read document procedure is responsible for reading
  161. ** the document data into ram in association with the FileRecHndl created by
  162. ** NewDocument(). */
  163.  
  164. OSErr            SaveDocument(FileRecHndl frHndl, WindowPtr window, short saveMode);
  165. /* This function does the human-interface thing for saving a document.  To
  166. ** actually write out the data, SaveDocument calls the designated write document
  167. ** procedure, which by default is WriteDocument.  The write document procedure is
  168. ** responsible for writing the document data to the designated file. */
  169.  
  170. void            ConvertOldToNewSFReply(SFReply *oldReply, StandardFileReply *newReply);
  171. /* When running on a pre-7.0 system, SFGetFile or SFPutFile is called.  Then
  172. ** ConvertOldToNewSFReply is called to convert the reply record to the new
  173. ** format.  This allows the rest of the application to use only a single
  174. ** record format. */
  175.  
  176. Boolean         DisplayGetFile(StandardFileReply *reply);
  177. /* Simple routine to display a list of files with our file type. */
  178.  
  179. Boolean         DisplayPutFile(StandardFileReply *reply);
  180. /* Displays the StandardFile PutFile dialog box. Fills out the passed reply
  181. ** record, and returns the sfGood field as a result. */
  182.  
  183. OSErr            UseDocResFile(FileRecHndl frHndl, short *oldRes, char perm);
  184. /* Use the resource fork for the designated document file.  This function
  185. ** also returns the old CurResFile, so you can set it back when you are done.
  186. ** Simply call this function, whether or not you have a resource fork.  If
  187. ** there isn’t a resource fork, then one will be created.  If there is one,
  188. ** but it isn’t open yet, it will be opened.  If it is already opened, it
  189. ** sets it as the current resource fork.  What more do you want? */
  190.  
  191. OSErr            CloseDocResFile(FileRecHndl frHndl);
  192. /* If there is a resource fork open for this document, this closes it. */
  193.  
  194. long            GetModNum(void);
  195. /* Get the modification number for the document.  TreeObj automatically increments this. */
  196.  
  197. Boolean            GetDocDirty(FileRecHndl frHndl);
  198. /* Get the dirty state of the document. */
  199.  
  200. Boolean            GetWindowDirty(WindowPtr window);
  201. /* Given a window, return the dirty state of the associated document. */
  202.  
  203. void            SetDocDirty(FileRecHndl frHndl);
  204. /* Set the document dirty. */
  205.  
  206. void            SetWindowDirty(WindowPtr window);
  207. /* Given a window, set the associated document as dirty. */
  208.  
  209. OSErr            FSpSetWD(FSSpec fss, short *wd, Boolean *created, short *oldWDRefNum);
  210. /* Given an FSSpec, set the working directory.  Working directories are a bad
  211. ** idea, but there are instances where they have to be used.  Some 3rd-party
  212. ** utilities don’t accept an FSSpec, and want just the file name.  In these
  213. ** instances you could generate a full pathname, but that isn’t so wonderful,
  214. ** either.  This function is here for cases where you are already having
  215. ** difficulties.  It is not here as the definitive solution.
  216. ** If you are going to use this function, it should be used as a one-shot deal.
  217. ** First, call FSpSetWD to temporarily set a working directory.  Then go about
  218. ** your business right away.  After you have finished with the working directory,
  219. ** which should be immediately after a create or open, call FSpResetWD, which
  220. ** gets rid of the wworking directory that you created.  Do not leave working
  221. ** directories around, as there is a limitied number that the system can handle. */
  222.  
  223. OSErr            FSpResetWD(short wd, Boolean created, short oldWDRefNum);
  224. /* Use this function to get rid of a working directory that was created via
  225. ** FSpSetWD.  Call this as soon as possible after creatig a working directory. */
  226.  
  227.  
  228.  
  229. /************** Init.c **************/
  230.  
  231. void            Initialize(short moreMasters, long minHeap, long minSpace,
  232.                            ProcPtr init1, ProcPtr init2);
  233. /* Given minHeap and minSpace values, get stuff going.  Also, we are passed
  234. ** in two procedure pointers.  If these are not nil, they are called at
  235. ** intermediate points during the initialization process.  The first proc
  236. ** is called after the Utilities.c standard initialization is complete.  The
  237. ** second proc is called very near the end of the initialization, but just
  238. ** prior to the menus being initialized. */
  239.  
  240. void            StartDocuments(void);
  241. /* This is startup code that shouldn’t have to change. */
  242.  
  243.  
  244.  
  245. /************** Print.c **************/
  246.  
  247. OSErr            PrintDocument(FileRecHndl frHndl, Boolean jobDlg, Boolean firstJob);
  248. void            DonePrinting(void);
  249. OSErr            PresentStyleDialog(FileRecHndl frHndl);
  250. /* These three functions are the generic print support for DTS.framework.
  251. ** You shouldn’t have to make any changes to these functions.  PrintDocument calls
  252. ** the designated image procedure.  The default procedure is ImageDocument.  You can
  253. ** change it if you wish.  ImageDocument images the document to either the window
  254. ** or to the printer.  The port is already set when ImageDocument is called to either
  255. ** the window’s port or the printer port.  The global variable gPrintPage is set
  256. ** so that you can determine if you are imaging for the window or for the printer.
  257. ** If gPrintPage is 0 then you are imaging for the window.  If gPrintPage is non-0,
  258. ** then that is the page you are imaging to the printer.  If you are printing, and
  259. ** have imaged the final page, your imaging code should set gPrintPage to 0.  This
  260. ** tells PrintDocument that you have done the final page.  The reason for this 
  261. ** is that the user could request to print pages 4 to 27, and you only have 14 pages
  262. ** in the document.  The imaging procedure "knows" how many pages the document
  263. ** has, and by having the imaging procedure return that it is finished, we eliminate
  264. ** the need for the generic print code to have to know how many pages are in the
  265. ** document.  Once your application has finished printing, it should call
  266. ** DonePrinting.  This frees up a THPrint handle that is used for job merging.  If
  267. ** you don’t call DonePrinting after printing, you get a memory leak. */
  268.  
  269.  
  270.  
  271. /************** TreeObj.c **************/
  272.  
  273. /* This is a complete package unto itself.  See the accompanying read-me for this guy,
  274. ** called "=Using TreeObj.c".  Also, check out the TreeObj.h header file.  Each function
  275. ** has a brief description of its use.  For an example of TreeObj usage, see DTS.Draw. */
  276.  
  277.  
  278.  
  279. /************** Window.c **************/
  280.  
  281. OSErr            DoNewWindow(FileRecHndl frHndl, WindowPtr *retWindow, WindowPtr relatedWindow,
  282.                             WindowPtr behind);
  283. /* This function is called by the application at appropriate times to give a document
  284. ** a window.  To create a document window, first a document is created by the application
  285. ** via NewDocument or OpenDocument.  If this succeeds then the application needs to create
  286. ** a window for the document.  To do this, the application calls DoNewWindow.  DoNewWindow
  287. ** calls the content initialization procedure, which by default is InitContent.
  288. ** If you want a different content initialization procedure, replace the
  289. ** default procedure pointer initContentProc with your own.  Normally however,
  290. ** you will just place your own content initialization procedure in the
  291. ** function InitContent.  It is possible though that your
  292. ** application has more than one document type and window type.  If this
  293. ** is the case, then you may very well want an alternate content
  294. ** initialization procedure.  If you do, you will want to replace the
  295. ** default procedure pointer after the NewDocument or OpenDocument
  296. ** call and before the call to DoNewWindow.  (You may place the code for
  297. ** replacing the content initialization procedure and imaging procedure
  298. ** in the function InitDocument.  The defaults are already established
  299. ** at that point.  You would just replace them with the alternates. */
  300.  
  301. void            NewWindowTitle(WindowPtr window, char *altTitle);
  302. /* Call this function if you want to change the title of the window.
  303. ** If you pass in nil, the window title will be gotten from the FSSpec of the document.
  304. ** If you pass in an alternate title in altTitle, that will be used instead
  305. ** of the document name. */
  306.  
  307. Boolean            DisposeAllWindows(void);
  308. Boolean            DisposeOneWindow(WindowPtr window, short saveMode);
  309. /* These functions do exactly as you would expect.  The saveMode indicates
  310. ** whether the window is being closed due to a close request, or due to the
  311. ** application being quit. */
  312.  
  313. WindowPtr        SetFilePort(FileRecHndl frHndl);
  314. /* This function sets the current port for the designated file.  It also returns
  315. ** the old port so that the port can be restored, if so desired. */
  316.  
  317. void            DoResizeWindow(WindowPtr window, short oldh, short oldv);
  318. /* This function is called when a window is resized.  This function needs to
  319. ** know the old size of the window.  The new size is determined by the
  320. ** dimensions of the window that was resized.  It moves and resizes the
  321. ** document scrollbars and growIcon (if any) to reflect the new size of
  322. ** the window.  It then calls the procedure stored in the procPtr field
  323. ** resizeContentProc, in case there is additional sizing necessary for the window.
  324. ** The default resizeContentProc is ResizeContent.  If you wish an alternate
  325. ** resizeContentProc, then you can replace the default in the function
  326. ** InitDocument, as the default is already established at this point. */
  327.  
  328. void            DoUpdateSeparate(WindowPtr window, RgnHandle *contRgn, RgnHandle *frameRgn);
  329. /* This function separates the update region into two portions.  One portion is
  330. ** the frame area, which consists of document scrollbars and growIcon (if any), plus
  331. ** an optional application-defined frame area.  The other portion is the rest of the
  332. ** window content that needs updating.  This separation is so that the document
  333. ** scrollbars can be updated first, and then this area can be clipped out of the rest
  334. ** of the updating so that the window content doesn’t draw over the document scrollbars
  335. ** and growIcon.  The clipping is managed with just the visRgn.  This frees up the clipRgn
  336. ** for application specific clipping. */
  337.  
  338. void            BeginContent(WindowPtr window);
  339. /* This function clips out the document scrollbars and growIcon from the updatable area.
  340. ** It also sets the origin of the port to the current document scrollbar values.
  341. ** BeginContent must be balanced by a call to EndContent.  BeginContent calls BeginUpdate,
  342. ** and BeginUpdate calls can’t be nested.  Due to this, BeginContent has a usage counter,
  343. ** which prevents nested calls to BeginUpdate.  BeginContent clips out the document
  344. ** scrollbar and growIcon area without involving the clipRgn so that the application is
  345. ** free to use the clipRgn as it sees fit.  The only caveat is that you can not modify the
  346. ** updateRgn between the BeginContent and EndContent calls, as anything contributed to the
  347. ** updateRgn between these calls will be lost.  If you need to do this, accumulate the areas
  348. ** in a separate region, call EndContent, and then call InvalRgn. */
  349.  
  350. void            EndContent(WindowPtr window);
  351. /* Calls to BeginContent must be balanced.  They also don’t nest.  EndContent undoes the
  352. ** clipping of the frame area that BeginContent invoked. */
  353.  
  354. void            AdjustScrollBars(WindowPtr window);
  355. /* You call this function whenever you change the amount that the arrows scroll
  356. ** the document, or whenever the document changes size.  These values are first
  357. ** stored in the document’s fileState structure.  Once the new values are in
  358. ** place, call AdjustScrollBars to affect all related changes. */
  359.  
  360. void            GetContentOrigin(WindowPtr window, Point *contOrg);
  361. /* This function returns the origin of the content of the window.  The value is
  362. ** gotten from the current value of the document scrollbars.  If a scrollbar
  363. ** is missing, the control value for that scrollbar is assumed to be 0.  Note that
  364. ** if you have sidebars in your document, the origin value has the sidebar value
  365. ** subtracted.  For example:  You have a top sidebar of 32 pixels, and the vertical
  366. ** scrollbar has a control value of 0.  This will return you a vertical origin of -32. */
  367.  
  368. void            SetContentOrigin(WindowPtr window, short newh, short newv);
  369. /* This function allows you to change the value of the document scrollbars,
  370. ** and by doing this, the document is scrolled to reflect the change, and
  371. ** an update event is generated for the document scroll.  Note that if you are
  372. ** using sidebars, you will have to subtract the value of the sidebar to get
  373. ** the expected results (see GetContentOrigin). */
  374.  
  375. void            GetContentRect(WindowPtr window, Rect *contRct);
  376. /* This function returns a rectangle that represents the content area of the
  377. ** window less the scrollbar and sidebar areas. */
  378.  
  379. void            SetDocSize(FileRecHndl frHndl, short hSize, short vSize);
  380. /* This function sets the document size to the new designated size.  It also
  381. ** makes appropriate adjustments to the scrollbars to reflect the new size. */
  382.  
  383. void            SetSidebarSize(FileRecHndl frHndl, short newLeft, short newTop);
  384. /* This function is used to set the size of the sidebars.  This is particularly
  385. ** useful for being able to show and hide a tool palette, or if you are using
  386. ** OCE and want to show a mailer at the top of your window.  The sidebar value
  387. ** should initially be set in File2.c, along with other document initialization.
  388. ** If you wish to change only one of the two sidebar sizes, send in a value of
  389. ** kwNoChange for the one that is not to change. */
  390.  
  391. void            SetScrollIndentSize(FileRecHndl frHndl, short newh, short newv);
  392. /* This function is used to set the size of the scrollbar indention.  The scrollbar
  393. ** indentnion allows you to put status information or document display related
  394. ** tool icons in line with the scrollbar.  They are considered part of the frame,
  395. ** as document scrollbars, the grow icon, and sidebars are.  The scrollbar indent value
  396. ** should initially be set in File2.c, in the same fashion as sidebar values are set.
  397. ** If you wish to change only one of the two scrollbar indent, send in a value of
  398. ** kwNoChange for the one that is not to change. */
  399.  
  400. FileRecHndl        GetNextDocument(WindowPtr window, OSType sftype);
  401. /* This function returns the file reference for the next application window
  402. ** of the designated kind.  If the window paramater is passed in as nil, it
  403. ** finds the top-most window.  If the window parameter is passed in as non-nil,
  404. ** it returns the next window.  If there is no next window found, it returns
  405. ** nil.  The sftype parameter restricts the finding of a window to a particular
  406. ** type.  If 0 is passed in for sftype, then any application window will match. */
  407.  
  408. WindowPtr        GetNextWindow(WindowPtr window, OSType sftype);
  409. /* This function behaves the same as GetNextDocument, but returns a window pointer
  410. ** instead of a file reference. */ 
  411.  
  412. WindowPtr        GetPreviousWindow(WindowPtr window);
  413. /* Returns the window in front of the window passed in.  If there is no window
  414. ** in front, it returns -1, not nil.  -1 is typically used to indicate the front
  415. ** of the window list, whereas nil is used to indicate the back.  This is done to
  416. ** stay consistent with the expectations of the toolbox. */
  417.  
  418. void            DoZoomWindow(WindowPtr window, EventRecord *event, short zoomDir);
  419. /* This function handles zooming of the document window.  It zooms it to the
  420. ** current monitor, up to the size of the document data. */
  421.  
  422. RgnHandle        DoCalcFrameRgn(WindowPtr window);
  423. /* This function calculates the region that encompasses the frame area of the document.
  424. ** The frame area consists of the document scrollbars, growIcon, sidebars, and an
  425. ** optional application-defined frame area.  The region is generated in global coordinates.
  426. ** Since the frame region may encompass more than the DTS.framework-supported scrollbars and
  427. ** growIcon, a procedure is first called to see if there is anything additional
  428. ** in the frame region.  The field calcFrameRgnProc holds the procedure pointer
  429. ** that contributes any extra to the frame region.  This function is passed an
  430. ** empty region.  If there is no additional contribution to the frame region,
  431. ** then the region should be left empty.  Once this procedure is returned from,
  432. ** the remaining frame portion is added to this region.  The remaining portion
  433. ** would consist of DTS.framework document scrollbars and a growIcon, if there
  434. ** are any for this window.  The field calcFrameRgnProc is initialized to the
  435. ** default value CalcFrameRgn.  If you wish an alternate drawFrameProc, then you
  436. ** can replace the default in the function InitDocument, as the default is
  437. ** already established at this point. */
  438.  
  439. RgnHandle        DoCalcScrollRgn(WindowPtr window);
  440. /* This function calculates the region that encompasses the document scrollbars
  441. ** and growIcon (if any).  The region is generated in global coordinates. */
  442.  
  443. void            DoContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  444. /* This function is called whenever the content portion of a window is clicked in.
  445. ** It simply calls the procedure pointer stored in the field contentClickProc.
  446. ** The field contentClickProc is initialized to ContentClick.  If you wish
  447. ** an alternate contentClickProc, then you can replace the default in the function
  448. ** InitDocument, as the default is already established at this point.  The
  449. ** boolean firstClick is true if you chose this window to handle first clicks, and
  450. ** if the click is actually a first click in the window.  A first click means that
  451. ** the window content was clicked on, but the window was not the front window.  The
  452. ** window has already been brought to the front, but you may wish the click to also
  453. ** be handled as a content click. */
  454.  
  455. void            DoDragWindow(WindowPtr window, EventRecord *event, Rect bounds);
  456. /* This function is used to drag a window.  We can’t use the toolbox function DragWindow,
  457. ** as the DTS.framework supports palettes.  Since we are supporting palettes, we have to
  458. ** be able to drag a window that isn’t the front, and bring it to the front of windows
  459. ** of its kind.  There is no way to coerce DragWindow to do this. */
  460.  
  461. void            DoDrawFrame(WindowPtr window);
  462. /* This function may be called when an update event occurs for the window.
  463. ** If the update region intersects the frame region (calculated by DoCalcFrameRgn),
  464. ** then a frame update occurs and this function is called.  It redraws the
  465. ** document scrollbars and growIcon (if any) and then calls the procedure stored
  466. ** in the field drawFrameProc, which has a default value of DrawFrame.  If you wish
  467. ** an alternate drawFrameProc, then you can replace the default in the function
  468. ** InitDocument, as the default is already established at this point. */
  469.  
  470. OSErr            DoFreeDocument(FileRecHndl frHndl);
  471. /* This is called to generically call the document’s freeing procedure.  This document
  472. ** is being disposed of, and any custom memory usage needs to be deallocated.  The
  473. ** frHndl itself will be disposed of, but any handle references that it contains
  474. ** need to be freed within the document’s freeing procedure.  The default freeing
  475. ** procedure is called FreeDocument(). */
  476.  
  477. OSErr            DoFreeWindow(FileRecHndl frHndl, WindowPtr window);
  478. /* This is called to generically call the document’s window freeing procedure.
  479. ** The window is going to be disposed of, and there may be related tasks to disposing
  480. ** of the window.  A document may have related windows or views.  This is where you
  481. ** would dispose of the related windows.  The default window freeing procedure is called
  482. ** FreeWindow(). */
  483.  
  484. OSErr            DoImageDocument(FileRecHndl frHndl);
  485. /* This function is called whenever the content portion of a window needs to be
  486. ** updated or printed.  It simply calls the procedure pointer stored in the field
  487. ** imageProc.  The field imageProc is initialized to ImageDocument.  If you wish
  488. ** an alternate imageProc, then you can replace the default in the function
  489. ** InitDocument, as the default is already established at this point. */
  490.  
  491. OSErr            DoInitContent(FileRecHndl frHndl, WindowPtr window);
  492. /* The window has been created, and is about to be displayed.  At this time, this
  493. ** function is called.  It generically calls the window content initialization procedure
  494. ** indicated within the frHndl.  The default window content initialization procedure is
  495. **  called InitContent(). */
  496.  
  497. void            DoKeyDown(EventRecord *event);
  498. /* DoKeyDown is first called by the application.  If the key is a menu key, the
  499. ** application function DoMenuCommand() is called.  If the key isn’t a menu
  500. ** key, DoKeyDown starts walking through the window list, giving each window an
  501. ** opportunity to handle the key.  Windows can handle it, eat it, or pass the key
  502. ** through to the next window.
  503. ** It gives each window a chance to handle the key by calling the key handling procedure
  504. ** stored in the frHndl.  The default procedure is called KeyDown().  Here are the
  505. ** rules for the window key handling procedure:
  506. **
  507. ** 1) If it handles the key, it returns true.  This completes the key handling.
  508. ** 2) If it doesn’t handle the key, it returns false.  However, there are two
  509. **    situations for not handling the key:
  510. **      a) The window wants windows behind it to try handling the key.
  511. **      b) The window wants nobody else to look at the key.
  512. **    This is what the boolean passThrough is for.  If the procedure wishes the next
  513. **    window to have a look at the key, it should set the boolean passThrough to true.
  514. **    passThrough is already initialized to false prior to calling the procedure, which
  515. **    is the common case, so the window key handling procedure only has to worry about
  516. **    setting it true.
  517. **
  518. ** If the window never processes keys and always passes them through to the next window,
  519. ** the contentKeyProc field in the frHndl should be set to nil.  This will indicate to
  520. ** DoKeyDown() that all keys should be passed through this window.  DTS.Draw has
  521. ** such a window.  The palette window doesn’t accept keys.  They are passed through
  522. ** to document windows that are behind the palette. */
  523.  
  524. void            DoMouseDown(EventRecord *event);
  525. /* Call this whenever a mouse down event occurs in the application.  Everything is
  526. ** handled.  Here’s what DoMouseDown() may do, and what it depends on:
  527. ** It handles:
  528. **     inContent
  529. **     inDrag
  530. **     inGoAway
  531. **     inGrow
  532. **     inMenuBar
  533. **     inSysWindow
  534. **     inZoomIn
  535. **     inZoomOut
  536. **
  537. ** inContent:
  538. **     a) If the window clicked on is a DA window, then bring the window to the front.
  539. **     b) If the window is not the top-most of its kind (palette,dialog,document), then
  540. **        it is made the top-most of its kind.  If the window has the kwDoFirstClick bit
  541. **        set, then DoContentClick is called, indicating that it is a first click.
  542. **
  543. ** inDrag:
  544. **     The window is dragged.  When released, if the command key was not held down at the
  545. **     time of the click, the window is made the top-most window of its kind.
  546. **
  547. ** inGoAway:
  548. **     The go-away is tracked.  If the document is dirty, then the user is asked if the
  549. **     document should first be saved.  The user can save, discard, or cancel.  All cases
  550. **     are handled.
  551. **
  552. ** inGrow:
  553. **     The window is grown.  Scrollbar adjustments are handled as they are in the 7.0 finder.
  554. **
  555. ** inMenuBar:
  556. **     MenuSelect() is called, then the application function DoMenuCommand() is called
  557. **     with the result of MenuSelect().
  558. **
  559. ** inSysWindow:
  560. **     SystemClick() is called.
  561. **
  562. ** inZoomIn:
  563. ** inZoomOut:
  564. **     The window is grown, according to the human-interface guidelines for zooming.
  565. **     The window is zoomed on the monitor that contains most of the window.  The zoom
  566. **     size is limited by the document size.  All of these details are handled. */
  567.  
  568. OSErr            DefaultFreeDocument(FileRecHndl frHndl);
  569. /* This procedure frees up the memory used by the document and undo hierarchies.
  570. ** If you are using the hierarchical document package, call this to free up all
  571. ** memory allocated for the document. */
  572.  
  573. OSErr            DoReadDocument(FileRecHndl frHndl);
  574. /* DoReadDocument() calls the specific read document procedure for the document.
  575. ** The specific procedure is stored in the frHndl field readDocumentProc.  The
  576. ** default value for readDocumentProc is ReadDocument().  It is the responsibility
  577. ** of the readDocument procedure to call the readDocumentHeader procedure.  This is
  578. ** done by calling DoReadDocumentHeader() from within the readDocumentProc. */
  579.  
  580. OSErr            DoReadDocumentHeader(FileRecHndl frHndl);
  581. /* DoReadDocumentHeader() calls the specific read document header procedure for the
  582. ** document.  The specific procedure is stored in the frHndl field readDocumentHeaderProc.
  583. ** The default value for readDocumentHeaderProc is DefaultReadDocumentHeader(). */
  584.  
  585. OSErr            DefaultReadDocument(FileRecHndl frHndl);
  586. /* You can call this from in your readDocumentProc.  DefaultReadDocument() first calls
  587. ** DoReadDocumentHeader() for the document.  It then reads in a hierarchical document
  588. ** by calling the TreeObj function ReadTree().  If this behavior isn’t what you want,
  589. ** you will need to write your own code to read in the file.  You can find an example
  590. ** custom read document in the sample application DTS.Chat. */
  591.  
  592. OSErr            DefaultReadDocumentHeader(FileRecHndl frHndl);
  593. /* This function reads in the default header for a file.  The header information is
  594. ** described by the structure DocHeaderInfo.  The typedef for this structure is in the
  595. ** file DTS.Lib.h.  This block of header information is saved at the beginning of the file.
  596. ** It is written to the data fork.  If you want the header information saved in the resource
  597. ** fork, you will have to have a custom readDocumentHeaderProc and writeDocumentHeaderProc.
  598. ** You can then simply read and write using the resource fork, instead of the data fork, as
  599. ** the defaults do. */
  600.  
  601. OSErr            DefaultReadDocumentFixup(FileRecHndl frHndl);
  602. /* If you are using the TreeObj hierarchical document package, some document fixup needs
  603. ** to be done after reading in the document.  Handle references were converted to ID’s
  604. ** when the document was saved.  These need to be converted back to handle references.
  605. ** Calling this function takes care of this.  DTS.Draw uses the hierarchical document
  606. ** package.  Take a look at its ReadDocument() function. */
  607.  
  608. OSErr            DoWriteDocument(FileRecHndl frHndl);
  609. /* DoWriteDocument() calls the specific write document procedure for the document.
  610. ** The specific procedure is stored in the frHndl field writeDocumentProc.  The
  611. ** default value for writeDocumentProc is WriteDocument().  It is the responsibility
  612. ** of the writeDocument procedure to call the writeDocumentHeader procedure.  This is
  613. ** done by calling DoWriteDocumentHeader() from within the writeDocumentProc. */
  614.  
  615. OSErr            DoWriteDocumentHeader(FileRecHndl frHndl);
  616. /* DoWriteDocumentHeader() calls the specific write document header procedure for the
  617. ** document.  The specific procedure is stored in the frHndl field writeDocumentHeaderProc.
  618. ** The default value for writeDocumentHeaderProc is DefaultWriteDocumentHeader(). */
  619.  
  620. OSErr            DefaultWriteDocument(FileRecHndl frHndl);
  621. /* You can call this from in your writeDocumentProc.  DefaultWriteDocument() first calls
  622. ** DoWriteDocumentHeader() for the document.  It then writes out a hierarchical document
  623. ** by calling the TreeObj function WriteTree().  If this behavior isn’t what you want,
  624. ** you will need to write your own code to write in the file.  You can find an example
  625. ** custom write document in the sample application DTS.Chat. */
  626.  
  627. OSErr            DefaultWriteDocumentHeader(FileRecHndl frHndl);
  628. /* This function writes out the default header for a file.  The header information is
  629. ** described by the structure DocHeaderInfo.  The typedef for this structure is in the
  630. ** file DTS.Lib.h.  This block of header information is saved at the beginning of the file.
  631. ** It is written to the data fork.  If you want the header information saved in the resource
  632. ** fork, you will have to have a custom readDocumentHeaderProc and writeDocumentHeaderProc.
  633. ** You can then simply read and write using the resource fork, instead of the data fork, as
  634. ** the defaults do. */
  635.  
  636. void            DoResizeContent(WindowPtr window, short oldh, short oldv);
  637. /* This function is called when a window has been resized.  It is possible that window
  638. ** contents have to be adjusted to match the new window size.  DoResizeContent() handles
  639. ** this.  DoResizeContent() uses a procedure stored in the frHndl field resizeContentProc.
  640. ** If resizeContentProc is not nil, then the procedure is called.  The default value for
  641. ** resizeContentProc is ResizeContent(). */
  642.  
  643. void            DoScrollFrame(WindowPtr window, long dx, long dy);
  644. /* Some applications may need to scroll the "frame" of the document along with the document
  645. ** contents.  This is common for applications with rulers, or other similar sidebar items.
  646. ** DoScrollFrame is called when document scrolling has occured.  DoScrollFrame() uses a
  647. ** procedure stored in the frHndl field scrollFrameProc.  If scrollFrameProc is not nil,
  648. ** then the procedure is called.  The default value for scrollFrameProc is ScrollFrame(). */
  649.  
  650. void            DoUndoFixup(FileRecHndl frHndl, Point contOrg, Boolean afterUndo);
  651. /* This function is called by the hierarchical document package in response to an undo/redo
  652. ** operation.  It is called prior to any undo information being applied to the document so
  653. ** that you can prepare the document for an undo.  It is also called after all undo tasks
  654. ** are performed on the document.  This last call is a chance for any additional cleanup
  655. ** that might have to occur.  Commonly this second call is used to reimage the document to
  656. ** show the document undone/redone.  DoUndoFixup() doesn’t actually do the work, as it doesn’t
  657. ** know what kind of document it was called for.  It simply looks in the frHndl at the field
  658. ** undoFixupProc.  If undoFixupProc is not nil, then the procedure is called.  The default
  659. ** value for undoFixupProc is UndoFixup(). */
  660.  
  661. WindowPtr        GetOldLocWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  662.                                 WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  663. /* This function is used in conjunction with the window attribute kwOpenAtOldLoc.  If the
  664. ** window is to be opened at the old location, then GetOldLocWindow() is used, instead of
  665. ** the Utilities.c function GetStaggeredWindow(). */
  666.  
  667. void            CleanSendBehind(WindowPtr window, WindowPtr afterWindow);
  668. /* This function is exactly what it would seem by the name.  SendBehind() has some problems
  669. ** in that it causes too much repainting of windows.  This function allows you to change the
  670. ** layer of a window very cleanly.  It also calls HiliteWindows(), which walks the window
  671. ** list and adjusts window hilighting for the various types of windows.  The top-most of a
  672. ** type is hilited, and all other windows of that type are unhilited. */
  673.  
  674. void            CleanSendInFront(WindowPtr window, WindowPtr beforeWindow);
  675. /* Again, this is exactly what it would seem.  See CleanSendBehind() for more information. */
  676.  
  677. void            HiliteWindows(void);
  678. /* This function is called to adjust the hilites of all windows.  Since DTS.framework
  679. ** supports palettes, there is possibly more than one hilited window.  The window manager
  680. ** doesn’t want to play this game, so certain additional functions had to be written.
  681. ** Basically, if you are using palettes, don’t make any window manager calls that change
  682. ** window hiliting.  Use CleanSendBehind() and CleanSendInFront().  These take care of
  683. ** window shuffling correctly.  Of course, there are calls you can’t avoid, such as
  684. ** closing a window.  If you do these operations directly, call HiliteWindows() afterwards. */
  685.  
  686. void            UnhiliteWindows(void);
  687. /* This is called to unhilite all windows.  DTS.framework allows for multiple hilited windows.
  688. ** All of them have to be unhilited prior to bringing up a modal dialog or alert.  Call this
  689. ** to unhilite all windows, do the modal dialog or alert, and then call HiliteWindows() to
  690. ** set the hiliting back to normal. */
  691.  
  692. void            DoUpdate(WindowPtr window);
  693. /* This is called when an update event is received for a window.  First, the
  694. ** updateRgn is separated into two parts.  Part 1 holds the window frame area,
  695. ** if any.  This is the area that might hold the scrollbars, grow icon, and
  696. ** any other application-specific frame parts.  This is drawn first.  Once
  697. ** this is done, the remainder of the updateRgn is drawn.  This allows us to
  698. ** handle all of the frame clipping without using the clipRgn.  By freeing up
  699. ** the clipRgn, we allow the application to use it without having to share. */
  700.  
  701. void            DoSetCursor(Cursor *cursor);
  702. /* Call this function to correctly set the cursor and to inform DTS.framework that
  703. ** you have specifically set the cursor.  This is used when you temporarily want to
  704. ** set the cursor, such as just before a slow operation.  For a slow operation, you
  705. ** may want to put up the wait cursor.  Use DoSetCursor() for this, and then when the
  706. ** operation is over and program control returns to the main event loop, the cursor
  707. ** will be recalculated to the current cursor for the mouse position. */
  708.  
  709. CursPtr            DoSetResCursor(short crsrID);
  710. /* This function serves the same purpose as DoSetCursor, except that you pass in
  711. ** a resID, instead of a cursor pointer.  The resource is loaded, the cursor is then
  712. ** copied into permanent memory, and then DoSetCursor is called with a pointer to
  713. ** the cursor image. */
  714.  
  715. void            DoWindowCursor(void);
  716. /* Call this function to calculate what the cursor should be for various windows.
  717. ** The result of this function is to set the cursor based on the current mouse position.
  718. ** In addition to setting the cursor, the cursor region is calculated.  The cursor
  719. ** region is kept in the global variable gCursorRgn.
  720. ** This function walks the window list, and for each document window, it calls the
  721. ** window’s cursor handling procedure.  The cursor handling procedure is stored in
  722. ** the frHndl field windowCursorProc.
  723. ** Here are the rules for cursor and gCursorRgn determination:
  724. **
  725. ** 1) See if the mouse position is currently inside the gCursorRgn.  If so, leave.
  726. ** 2) Since the mouse position is outside the current gCursorRgn, we need to recalculate
  727. **    the cursor.  Set the gCursorRgn to wide-open.  From now on, we will eliminate areas
  728. **    from gCursorRgn that don’t apply to the new mouse location and new cursor.
  729. ** 3) For each visible window (starting with the front window):
  730. **    a) If the windowCursorProc is nil and the mouse position is over the structure region
  731. **       of the window, set the cursor to an arrow and intersect the gCursorRgn with the
  732. **       structure region of the window.  This limits the cursor to the area of the window
  733. **       that is visible.
  734. **    b) If the windowCursorProc is nil and the mouse position is outside the structure region
  735. **       of the window, diff out the structure region from gCursorRgn and proceed to the next
  736. **       visible window in the window list.
  737. **    c) If the windowCursorProc is not nil, call the procedure.  Note that the procedure is
  738. **       called whether or not the mouse location is over the window.  This is to allow the
  739. **       procedure to determine if it should be the last window checked.
  740. **       The proc’s job is as follows:
  741. **       1) If the cursor is over a position that is determined by the window, then
  742. **          the proc removes other areas from gCursorRgn.  Note that it should not
  743. **          simply set the area to what it "thinks" is the correct area.  This window
  744. **          may not be the front-most.  Other windows will have already been subtracted
  745. **          from gCursorRgn.  The resultant gCursorRgn is the correct cursor area,
  746. **          and should be passed to WaitNextEvent calls in the application.  Also,
  747. **          the cursor should be set to the correct cursor, of course.
  748. **          You should also return true, as the cursor has been determined.
  749. **          The rule of thumb for what you should do to the gCursorRgn is that you should
  750. **          calculate the cursor region as if the window was the top window.  Once this
  751. **          is done, intersect the gCursorRgn with this region.  The result should be
  752. **          stored in gCursorRgn.
  753. **          Since you determined a cursor and gCursorRgn in this case, you should return
  754. **          true.  Returning true indicates to DoWindowCursor() that the cursor has been
  755. **          determined, and that it should stop processing windows.
  756. **       2) If the cursor is not over a position for this window, then you should
  757. **          return.  You will either pass back true or false.  If you don’t wish
  758. **          windows behind this window to have a shot at cursor determination, then
  759. **          return true.  This states that the cursor is "determined".  It is, in the
  760. **          sense that no further determination will occur.  If you return false, then
  761. **          other windows get a shot at determining the cursor.  If there are no other windows,
  762. **          then the cursor is set to an arrow, and gCursorRgn is set to the area that is outside
  763. **          all windows for the application.
  764. **          (Common case:)  If you don’t want windows behind this one to determine the cursor:
  765. **          a) Set the cursor to an arrow.  Since you are outside this window, the cursor
  766. **             should be an arrow.  The cursor may be over the desktop or menubar, or some
  767. **             other window that isn’t the top-most window.  All of these cases should have
  768. **             an arrow cursor.  Also, you need to diff out the window’s structure region from
  769. **             gCursorRgn.  By diffing it out, you will get mouse-moved events when the
  770. **             cursor is moved back over this window.
  771. **          b) Return true.  This tells DoWindowCursor() that the cursor has been determined.
  772. **          (Uncommon case:)  If you want windows behind this one to possibly determine the cursor:
  773. **             Return false.  That’s it.  DTS.framework will automatically remove the structure
  774. **             region for this window from gCursorRgn if you return false.  If you return false,
  775. **             DTS.framework proceeds to the next window, if there is one.  If there are no more
  776. **             windows behind this one, then DTS.framework sets the cursor to an arrow, and
  777. **             the resultant gCursorRgn will have all of the structure regions for the windows
  778. **             removed from it. */
  779.  
  780. WindowPtr            FrontWindowOfType(short wkind);
  781. /* Since DTS.framework supports three distinct categories of windows (document/palette/dialog),
  782. ** it is often necessary to get the front-most window of a certain type.  Use this function
  783. ** to accomplish this.  Basically, this takes the place of FrontWindow() if you have more
  784. ** than one category of window in your application. */
  785.  
  786.